<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="组织编码" prop="fnumber">
        <el-input
          v-model="queryParams.fnumber"
          placeholder="请输入组织编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组织名称" prop="fname">
        <el-input
          v-model="queryParams.fname"
          placeholder="请输入组织名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="盖亚组织编码" prop="fgynumber">
        <el-input
          v-model="queryParams.fgynumber"
          placeholder="请输入盖亚组织编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="盖亚组织名称" prop="fgyname">
        <el-input
          v-model="queryParams.fgyname"
          placeholder="请输入盖亚组织名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item><!--
      <el-form-item label="组织级别" prop="fzzlevel">
        <el-input
          v-model="queryParams.fzzlevel"
          placeholder="请输入组织级别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属一级公司" prop="fonecompany">
        <el-input
          v-model="queryParams.fonecompany"
          placeholder="请输入所属一级公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属二级公司" prop="ftwocompany">
        <el-input
          v-model="queryParams.ftwocompany"
          placeholder="请输入所属二级公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否当月缴纳社保公积金" prop="fisdysb">
        <el-select v-model="queryParams.fisdysb" placeholder="请选择是否当月缴纳社保公积金" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否生产部门" prop="fisscbm">
        <el-select v-model="queryParams.fisscbm" placeholder="请选择是否生产部门" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否辅助生产部门" prop="fisfzscbm">
        <el-select v-model="queryParams.fisfzscbm" placeholder="请选择是否辅助生产部门" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否销售部门" prop="fisxsbm">
        <el-select v-model="queryParams.fisxsbm" placeholder="请选择是否销售部门" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否行政部门" prop="fisxzbm">
        <el-select v-model="queryParams.fisxzbm" placeholder="请选择是否行政部门" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="记账公司" prop="fjzgs">
        <el-input
          v-model="queryParams.fjzgs"
          placeholder="请输入记账公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="凭证字" prop="fpzz">
        <el-input
          v-model="queryParams.fpzz"
          placeholder="请输入凭证字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金单位" prop="fgjjdw">
        <el-input
          v-model="queryParams.fgjjdw"
          placeholder="请输入公积金单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金金融机构" prop="fgjjjrjg">
        <el-input
          v-model="queryParams.fgjjjrjg"
          placeholder="请输入公积金金融机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金账号" prop="fgjjzh">
        <el-input
          v-model="queryParams.fgjjzh"
          placeholder="请输入公积金账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保单位" prop="fsbdw">
        <el-input
          v-model="queryParams.fsbdw"
          placeholder="请输入社保单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保金融机构" prop="fsbjrjg">
        <el-input
          v-model="queryParams.fsbjrjg"
          placeholder="请输入社保金融机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保账号" prop="fsbzh">
        <el-input
          v-model="queryParams.fsbzh"
          placeholder="请输入社保账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否实体成本中心" prop="fisbizcost">
        <el-select v-model="queryParams.fisbizcost" placeholder="请选择是否实体成本中心" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否实体财务组织" prop="fisbizcompany">
        <el-select v-model="queryParams.fisbizcompany" placeholder="请选择是否实体财务组织" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否封存" prop="fisousealup">
        <el-select v-model="queryParams.fisousealup" placeholder="请选择是否封存" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="组织层级" prop="flevel">
        <el-input
          v-model="queryParams.flevel"
          placeholder="请输入组织层级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否叶子节点" prop="fisleaf">
        <el-select v-model="queryParams.fisleaf" placeholder="请选择是否叶子节点" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="制单人" prop="fcreator">
        <el-input
          v-model="queryParams.fcreator"
          placeholder="请输入制单人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制单时间" prop="fcreatetime">
        <el-date-picker clearable
          v-model="queryParams.fcreatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择制单时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最后修改人" prop="flastupdateuser">
        <el-input
          v-model="queryParams.flastupdateuser"
          placeholder="请输入最后修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后修改时间" prop="flastupdatetime">
        <el-date-picker clearable
          v-model="queryParams.flastupdatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择最后修改时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-view"
          size="mini"
          :disabled="single"
          @click="handleView"
        >查看</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wfzBaseData:baseunit:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wfzBaseData:baseunit:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wfzBaseData:baseunit:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wfzBaseData:baseunit:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList,getGYList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseunitList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="fid" />
      <el-table-column label="组织编码" align="center" prop="fnumber" />
      <el-table-column label="组织名称" align="center" prop="fname" />
      <el-table-column label="盖亚组织编码" align="center" prop="fgynumber" />
      <el-table-column label="盖亚组织名称" align="center" prop="fgyname" />
      <el-table-column label="组织级别" align="center" prop="fzzlevel" />
      <el-table-column label="成本中心属性" align="center" prop="fcosttype">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cost_type" :value="scope.row.fcosttype"/>
        </template>
      </el-table-column>
      <el-table-column label="所属一级公司" align="center" prop="fonecompany" />
      <el-table-column label="所属二级公司" align="center" prop="ftwocompany" />
      <el-table-column label="是否当月缴纳社保公积金" align="center" prop="fisdysb">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisdysb"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="是否生产部门" align="center" prop="fisscbm">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisscbm"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="是否辅助生产部门" align="center" prop="fisfzscbm">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisfzscbm"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="是否销售部门" align="center" prop="fisxsbm">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisxsbm"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="是否行政部门" align="center" prop="fisxzbm">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisxzbm"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="记账公司" align="center" prop="fjzgs" />
      <el-table-column label="凭证字" align="center" prop="fpzz" />
      <el-table-column label="公积金单位" align="center" prop="fgjjdw" />
      <el-table-column label="公积金金融机构" align="center" prop="fgjjjrjg" />
      <el-table-column label="公积金账号" align="center" prop="fgjjzh" />
      <el-table-column label="社保单位" align="center" prop="fsbdw" />
      <el-table-column label="社保金融机构" align="center" prop="fsbjrjg" />
      <el-table-column label="社保账号" align="center" prop="fsbzh" />
      <el-table-column label="是否实体成本中心" align="center" prop="fisbizcost">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisbizcost"/>
        </template>
      </el-table-column>
      <el-table-column label="是否实体财务组织" align="center" prop="fisbizcompany">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisbizcompany"/>
        </template>
      </el-table-column>
      <el-table-column label="是否封存" align="center" prop="fisousealup">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisousealup"/>
        </template>
      </el-table-column>
      <el-table-column label="组织层级" align="center" prop="flevel" />
      <el-table-column label="是否叶子节点" align="center" prop="fisleaf">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.fisleaf"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="fstate">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bill_state" :value="scope.row.fstate"/>
        </template>
      </el-table-column>
      <el-table-column label="制单人" align="center" prop="fcreator" />
      <el-table-column label="制单时间" align="center" prop="fcreatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fcreatetime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后修改人" align="center" prop="flastupdateuser" />
      <el-table-column label="最后修改时间" align="center" prop="flastupdatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.flastupdatetime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wfzBaseData:baseunit:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wfzBaseData:baseunit:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改组织-成本中心对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="250px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="组织编码" prop="fnumber">
              <el-input v-model="form.fnumber" placeholder="请输入组织编码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="组织名称" prop="fname">
              <el-input v-model="form.fname" placeholder="请输入组织名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--        <el-form-item label="盖亚组织编码" prop="fgynumber">-->
            <!--          <el-input v-model="form.fgynumber" placeholder="请输入盖亚组织编码" />-->
            <!--        </el-form-item>-->

            <el-form-item label="盖亚组织编码" prop="fgynumber">
              <el-select v-model="form.fgynumber" filterable placeholder="请选择盖亚组织" clearable  size="small">
                <el-option
                  v-for="item in fgynumbers"
                  :key="item.fnumber"
                  :label="item.fname"
                  :value="item.fnumber">
                </el-option>
              </el-select>
            </el-form-item>
            <!--        //将该输入框隐藏，不需要该输入框显示在前端-->
            <el-form-item label="盖亚组织名称" prop="fgyname" style="display: none">
              <el-input v-model="form.fgyname" placeholder="请输入盖亚组织名称" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="组织级别" prop="fzzlevel">
              <el-input v-model="form.fzzlevel" placeholder="请输入组织级别" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="成本中心属性" prop="fcosttype">
              <el-select v-model="form.fcosttype" placeholder="请选择成本中心属性">
                <el-option
                  v-for="dict in dict.type.cost_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属一级公司" prop="fonecompany">
              <el-input v-model="form.fonecompany" placeholder="请输入所属一级公司" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="所属二级公司" prop="ftwocompany">
              <el-input v-model="form.ftwocompany" placeholder="请输入所属二级公司" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否当月缴纳社保公积金">
              <el-radio-group v-model="form.fisdysb">
                <el-radio
                  v-for="dict in dict.type.yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="是否生产部门">-->
<!--              <el-radio-group v-model="form.fisscbm">-->
<!--                <el-radio-->
<!--                  v-for="dict in dict.type.yes_no"-->
<!--                  :key="dict.value"-->
<!--                  :label="parseInt(dict.value)"-->
<!--                >{{dict.label}}</el-radio>-->
<!--              </el-radio-group>-->
<!--            </el-form-item>-->
<!--          </el-col>-->

          <el-col :span="8">
            <el-form-item label="记账公司" prop="fjzgs">
              <el-input v-model="form.fjzgs" placeholder="请输入记账公司" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
<!--            <el-form-item label="是否辅助生产部门">-->
<!--              <el-radio-group v-model="form.fisfzscbm">-->
<!--                <el-radio-->
<!--                  v-for="dict in dict.type.yes_no"-->
<!--                  :key="dict.value"-->
<!--                  :label="parseInt(dict.value)"-->
<!--                >{{dict.label}}</el-radio>-->
<!--              </el-radio-group>-->
<!--            </el-form-item>-->
          </el-col>
          <el-col :span="8">
<!--            <el-form-item label="是否销售部门">-->
<!--              <el-radio-group v-model="form.fisxsbm">-->
<!--                <el-radio-->
<!--                  v-for="dict in dict.type.yes_no"-->
<!--                  :key="dict.value"-->
<!--                  :label="parseInt(dict.value)"-->
<!--                >{{dict.label}}</el-radio>-->
<!--              </el-radio-group>-->
<!--            </el-form-item>-->
          </el-col>
          <el-col :span="8">
<!--            <el-form-item label="是否行政部门">-->
<!--              <el-radio-group v-model="form.fisxzbm">-->
<!--                <el-radio-->
<!--                  v-for="dict in dict.type.yes_no"-->
<!--                  :key="dict.value"-->
<!--                  :label="parseInt(dict.value)"-->
<!--                >{{dict.label}}</el-radio>-->
<!--              </el-radio-group>-->
<!--            </el-form-item>-->
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="凭证字" prop="fpzz">
              <el-input v-model="form.fpzz" placeholder="请输入凭证字" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公积金单位" prop="fgjjdw">
              <el-input v-model="form.fgjjdw" placeholder="请输入公积金单位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公积金金融机构" prop="fgjjjrjg">
              <el-input v-model="form.fgjjjrjg" placeholder="请输入公积金金融机构" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="公积金账号" prop="fgjjzh">
              <el-input v-model="form.fgjjzh" placeholder="请输入公积金账号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="社保单位" prop="fsbdw">
              <el-input v-model="form.fsbdw" placeholder="请输入社保单位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="社保金融机构" prop="fsbjrjg">
              <el-input v-model="form.fsbjrjg" placeholder="请输入社保金融机构" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="社保账号" prop="fsbzh">
              <el-input v-model="form.fsbzh" placeholder="请输入社保账号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否实体成本中心">
              <el-radio-group v-model="form.fisbizcost">
                <el-radio
                  v-for="dict in dict.type.yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否实体财务组织">
              <el-radio-group v-model="form.fisbizcompany">
                <el-radio
                  v-for="dict in dict.type.yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="是否封存">
              <el-radio-group v-model="form.fisousealup">
                <el-radio
                  v-for="dict in dict.type.yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="组织层级" prop="flevel">
              <el-input v-model="form.flevel" placeholder="请输入组织层级" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否叶子节点">
              <el-radio-group v-model="form.fisleaf">
                <el-radio
                  v-for="dict in dict.type.yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="状态" prop="fstate">
          <el-select v-model="form.fstate" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.bill_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-row>
          <el-col :span="12">
            <el-form-item label="制单人" prop="fcreator" v-show="show">
              <el-input v-model="form.fcreator" placeholder="请输入制单人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="制单时间" prop="fcreatetime" v-show="show">
              <el-date-picker clearable
                              v-model="form.fcreatetime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择制单时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="最后修改人" prop="flastupdateuser" v-show="show">
              <el-input v-model="form.flastupdateuser" placeholder="请输入最后修改人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最后修改时间" prop="flastupdatetime" v-show="show">
              <el-date-picker clearable
                              v-model="form.flastupdatetime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择最后修改时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

<!--        <el-form-item label="制单人" prop="fcreator">-->
<!--          <el-input v-model="form.fcreator" placeholder="请输入制单人" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="制单时间" prop="fcreatetime">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.fcreatetime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择制单时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="最后修改人" prop="flastupdateuser">-->
<!--          <el-input v-model="form.flastupdateuser" placeholder="请输入最后修改人" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="最后修改时间" prop="flastupdatetime">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.flastupdatetime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择最后修改时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!show">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGybaseunit } from "@/api/basedata/gybaseunit";
import { listBaseunit, getBaseunit, delBaseunit, addBaseunit, updateBaseunit } from "@/api/basedata/baseunit";


export default {
  name: "Baseunit",
  dicts: ['yes_no','bill_state','cost_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 组织-成本中心表格数据
      baseunitList: [],
      // 盖亚组织列表
      fgynumbers: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示控件
      show: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fnumber: null,
        fname: null,
        fgynumber: null,
        fgyname: null/*,
        fzzlevel: null,
        fcosttype: null,
        fonecompany: null,
        ftwocompany: null,
        fisdysb: null,
        fisscbm: null,
        fisfzscbm: null,
        fisxsbm: null,
        fisxzbm: null,
        fjzgs: null,
        fpzz: null,
        fgjjdw: null,
        fgjjjrjg: null,
        fgjjzh: null,
        fsbdw: null,
        fsbjrjg: null,
        fsbzh: null,
        fisbizcost: null,
        fisbizcompany: null,
        fisousealup: null,
        flevel: null,
        fisleaf: null,
        fcreator: null,
        fcreatetime: null,
        flastupdateuser: null,
        flastupdatetime: null*/
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fnumber: [
          { required: true, message: "组织编码不能为空", trigger: "blur" }
        ],
        fname: [
          { required: true, message: "组织名称不能为空", trigger: "blur" }
        ],
        fgynumber: [
          { required: true, message: "盖亚组织编码不能为空", trigger: "change" }
        ],
        fgyname: [
          { required: true, message: "盖亚组织名称不能为空", trigger: "blur" }
        ],
        fzzlevel: [
          { required: true, message: "组织级别不能为空", trigger: "blur" }
        ],
        fcosttype: [
          { required: true, message: "成本中心属性不能为空", trigger: "change" }
        ],
        fisdysb: [
          { required: true, message: "是否当月缴纳社保公积金不能为空", trigger: "blur" }
        ],
        fisscbm: [
          { required: true, message: "是否生产部门不能为空", trigger: "blur" }
        ],
        fisfzscbm: [
          { required: true, message: "是否辅助生产部门不能为空", trigger: "blur" }
        ],
        fisxsbm: [
          { required: true, message: "是否销售部门不能为空", trigger: "blur" }
        ],
        fisxzbm: [
          { required: true, message: "是否行政部门不能为空", trigger: "blur" }
        ],
        fjzgs: [
          { required: true, message: "记账公司不能为空", trigger: "blur" }
        ],
        fpzz: [
          { required: true, message: "凭证字不能为空", trigger: "blur" }
        ],
        fgjjdw: [
          { required: true, message: "公积金单位不能为空", trigger: "blur" }
        ],
        fgjjjrjg: [
          { required: true, message: "公积金金融机构不能为空", trigger: "blur" }
        ],
        fgjjzh: [
          { required: true, message: "公积金账号不能为空", trigger: "blur" }
        ],
        fsbdw: [
          { required: true, message: "社保单位不能为空", trigger: "blur" }
        ],
        fsbjrjg: [
          { required: true, message: "社保金融机构不能为空", trigger: "blur" }
        ],
        fsbzh: [
          { required: true, message: "社保账号不能为空", trigger: "blur" }
        ],
        fisbizcost: [
          { required: true, message: "是否实体成本中心不能为空", trigger: "blur" }
        ],
        fisbizcompany: [
          { required: true, message: "是否实体财务组织不能为空", trigger: "blur" }
        ],
        fisousealup: [
          { required: true, message: "是否封存不能为空", trigger: "blur" }
        ],
        flevel: [
          { required: true, message: "组织层级不能为空", trigger: "blur" }
        ],
        fisleaf: [
          { required: true, message: "是否叶子节点不能为空", trigger: "blur" }
        ],
        fstate: [
          { required: true, message: "状态不能为空", trigger:"blur"}
        ]
        /*,
        fcreator: [
          { required: true, message: "制单人不能为空", trigger: "blur" }
        ],
        fcreatetime: [
          { required: true, message: "制单时间不能为空", trigger: "blur" }
        ],
        flastupdateuser: [
          { required: true, message: "最后修改人不能为空", trigger: "blur" }
        ],
        flastupdatetime: [
          { required: true, message: "最后修改时间不能为空", trigger: "blur" }
        ]*/
      }
    };
  },
  created() {
    this.getList();
    this.getGYList();
  },
  methods: {
    /** 查询组织-成本中心列表 */
    getList() {
      this.loading = true;
      listBaseunit(this.queryParams).then(response => {
        this.baseunitList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询盖亚组织列表 */
    getGYList(){
      listGybaseunit().then(response => {
        this.fgynumbers = response.rows;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fid: null,
        fnumber: null,
        fname: null,
        fgynumber: null,
        fgyname: null,
        fzzlevel: null,
        fcosttype: null,
        fonecompany: null,
        ftwocompany: null,
        fisdysb: 0,
        fisscbm: 0,
        fisfzscbm: 0,
        fisxsbm: 0,
        fisxzbm: 0,
        fjzgs: null,
        fpzz: null,
        fgjjdw: null,
        fgjjjrjg: null,
        fgjjzh: null,
        fsbdw: null,
        fsbjrjg: null,
        fsbzh: null,
        fisbizcost: 0,
        fisbizcompany: 0,
        fisousealup: 0,
        flevel: null,
        fisleaf: 0,
        fcreator: null,
        fcreatetime: null,
        flastupdateuser: null,
        flastupdatetime: null,
        fstate: null,
        show: false
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const fid = row.fid || this.ids
      getBaseunit(fid).then(response => {
        this.form = response.data;
        this.open = true;
        this.show = true;
        this.title = "查看组织-成本中心";
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.show = false;
      this.title = "添加组织-成本中心";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fid = row.fid || this.ids
      getBaseunit(fid).then(response => {
        this.form = response.data;
        this.open = true;
        this.show = false;
        this.title = "修改组织-成本中心";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fid != null) {
            updateBaseunit(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBaseunit(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fids = row.fid || this.ids;
      this.$modal.confirm('是否确认删除组织-成本中心编号为"' + fids + '"的数据项？').then(function() {
        return delBaseunit(fids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basedata/baseunit/export', {
        ...this.queryParams
      }, `baseunit_${new Date().getTime()}.xlsx`)
    }
  },
  watch: {
    //监听盖亚组织的变化，使其能够实时将盖亚名称改变
    'form.fgynumber'(val) {
      console.log(val)
        var fgynumbers = this.fgynumbers;
      console.log(fgynumbers)
        //获取到对应的组织
        var unit = fgynumbers.filter(function (item){
          return item.fnumber === val;
        });
      console.log(unit)

      this.form.fgyname = unit[0].fname;
      console.log(this)
      console.log(this.form.fnumber)
      console.log(this.form.fname)
      console.log(this.form.fgyname)
      console.log(this.form.fzzlevel)

    }
  }
};
</script>
